<template>
  <div>
    <bread>
      <span slot="second">订单管理</span>
      <span slot="third">订单列表</span>
    </bread>
    <el-card>
      <!-- 搜索框 -->
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容">
            <el-button icon="el-icon-search" slot="append"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 中间内容条 -->
      <el-table :data="orderList" stripe border>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template v-slot="scope">
            <el-tag v-if="scope.pay_status === '1'" type="success">已付款</el-tag>
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template v-slot="scope">{{scope.row.create_time|dateFormat}}</template>
        </el-table-column>
        <el-table-column label="操作">
          <el-button type="primary" icon="el-icon-edit" size="mini" @click="showBox"></el-button>
          <el-button type="success" icon="el-icon-location" size="mini" @click="showProgressBox"></el-button>
        </el-table-column>
      </el-table>

      <!-- 分页部分 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      ></el-pagination>
      <!-- 修改地址 -->
      <el-dialog title="输入省市" :visible.sync="CityProvVisible" width="50%" @close="addressClose">
        <el-form
          :model="addressForm"
          :rules="addressrules"
          ref="addressFormRef"
          label-width="100px"
        >
          <el-form-item label="省市区/县" prop="address1">
            <el-cascader :options="citydata" v-model="addressForm.address1"></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="address2">
            <el-input v-model="addressForm.address2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="CityProvVisible = false">确定</el-button>
          <el-button @click="CityProvVisible = false">取消</el-button>
        </span>
      </el-dialog>

      <!-- 物流进度 -->
      <el-dialog title="物流信息" :visible.sync="progressVisible" width="50%" @close="addressClose">
        <el-form v-model="prgressMes" ref="addressFormRef" label-width="100px">
          <el-form-item label="物流信息">
            <div class="radio">
              排序：
              <el-radio-group v-model="reverse">
                <el-radio :label="true">倒序</el-radio>
                <el-radio :label="false">正序</el-radio>
              </el-radio-group>
            </div>
            <el-timeline :reverse="reverse">
              <el-timeline-item
                v-for="(prgressMes, index) in prgressMes"
                :key="index"
                :timestamp="prgressMes.time"
              >{{prgressMes.context}}</el-timeline-item>
            </el-timeline>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="progressVisible = false">确定</el-button>
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import cityData from './citydata.js'
import Bread from '../../base/breadcrumb'
export default {
  components: {
    bread: Bread
  },
  data() {
    return {
      reverse: true,
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      orderList: [],
      CityProvVisible: false,
      addressForm: {
        address1: [],
        address2: ''
      },
      addressrules: {
        address1: [
          { required: true, message: '请填写省市/县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请填写具体地址', trigger: 'blur' }
        ]
      },
      citydata: cityData,
      progressVisible: false,
      prgressMes: []
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取数据失败')
      }
      console.log(res.data)
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange(newpagesize) {
      this.queryInfo.pagesize = newpagesize
      this.getOrderList()
    },
    handleCurrentChange(newpage) {
      this.queryInfo.pagenum = newpage
      this.getOrderList()
    },
    showBox() {
      this.CityProvVisible = true
    },
    addressClose() {
      this.$refs.addressFormRef.resetFields()
    },
    async showProgressBox() {
      this.progressVisible = true
      const { data: res } = await this.$http.get(`/kuaidi/${1106975712662}`)
      if (res.meta.status !== 200) {
        return this.$message.error('获取物流信息失败')
      }
      console.log(res.data)
      this.prgressMes = res.data
    }
  }
}
</script>

<style lang="less" scoped>
</style>
